# coding=utf-8

import getopt
import sys
import traceback

import rdb.facade as rdb
import schema.facade as schema
import s1.facade as s1
import audio.facade as audio
import excel.facade as excel
import check.facade as check
import quiz.facade as quiz
import syllable.facade as syllable
# import story_context.facade as story
reload(sys)
sys.setdefaultencoding('utf-8')


def help():
    usage = """Usage:python main.py 
--help | -h    print this usage.
--org          parse a org mode file.
--schema       generate sql files from excel file.
--s1           generate s1 symbols.
--excel        excel tools.
--audio        count syllables.
--quiz         generate quiz json.
--check        check course column. 
--rdb          rdb utils.
--syllable     word is splited by syllable"""
# --story        a story context of a group word"""
    print(usage)


def main():
    """"""
    # help()

try:
    opts, args = getopt.getopt(sys.argv[1:], "h", [
        "help",
        "org",
        "rdb",
        "s1",
        "excel",
        "audio",
        "check",
        "quiz",
        "schema",
        "syllable",
        # "story"
    ])
except getopt.GetoptError as err:
    print(str(err))
    help()
    sys.exit(2)

try:
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            help()
            sys.exit()
        elif opt == "--rdb":
            rdb.test()
        elif opt == "--schema":
            schema.main()
        elif opt == "--s1":
            s1.process()
        elif opt == "--excel":
            excel.process()
        elif opt == "--audio":
            audio.process()
        elif opt == "--check":
            check.process()
        elif opt == "--quiz":
            quiz.process()
        elif opt == "--syllable":
            syllable.process()
        # elif opt == "--story":
        #     story.process()
        else:
            help()
            sys.exit()
except Exception as e:
    print(traceback.format_exc(e))

if __name__ == "__main__":
    main()
